package com.pacy.pacybaseproject.activitys;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;

import android.os.Bundle;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.blankj.utilcode.util.FragmentUtils;
import com.blankj.utilcode.util.LogUtils;
import com.flyco.tablayout.listener.CustomTabEntity;
import com.flyco.tablayout.listener.OnTabSelectListener;
import com.pacy.pacybaseproject.BR;
import com.pacy.pacybaseproject.R;
import com.pacy.pacybaseproject.activitys.routing.RoutingBusFragment;
import com.pacy.pacybaseproject.activitys.routing.RoutingTaxiFragment;
import com.pacy.pacybaseproject.activitys.routing.RoutingWalkFragment;
import com.pacy.pacybaseproject.base.BaseXActivity;
import com.pacy.pacybaseproject.beans.TabBean;
import com.pacy.pacybaseproject.databinding.ActivityRoutingBinding;
import com.pacy.pacybaseproject.viewmodels.RoutingViewModel;
import com.xuexiang.xui.utils.StatusBarUtils;

import java.util.ArrayList;
import java.util.List;

import me.goldze.mvvmhabit.utils.KLog;

/**
 * 路线规划
 */
public class RoutingActivity extends BaseXActivity<ActivityRoutingBinding, RoutingViewModel> {
    private ArrayList<CustomTabEntity> tabs = new ArrayList<>();
    private List<Fragment> fragments=new ArrayList<>();



    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_routing;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public void initData() {
        super.initData();
        initTab();
        LinearLayout.LayoutParams params=new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, StatusBarUtils.getStatusBarHeight(RoutingActivity.this));
        binding.view.setLayoutParams(params);
        fragments.add(RoutingBusFragment.newInstance("公交"));
        fragments.add(RoutingTaxiFragment.newInstance("打车"));
        fragments.add(RoutingWalkFragment.newInstance("步行"));
        FragmentUtils.add(getSupportFragmentManager(),fragments.get(0),R.id.fly);
        FragmentUtils.add(getSupportFragmentManager(),fragments.get(1),R.id.fly);
        FragmentUtils.add(getSupportFragmentManager(),fragments.get(2),R.id.fly);
        FragmentUtils.showHide(0,fragments);
    }

    private void initTab(){
        tabs.add(new TabBean("15分钟",R.drawable.gongjiao_true,R.drawable.gongjiao_false));
        tabs.add(new TabBean("10分钟",R.drawable.taxi_true,R.drawable.taxi_false));
        tabs.add(new TabBean("35分钟",R.drawable.buxing_true,R.drawable.buxing_false));
        binding.tabLayout.setTabData(tabs);
        binding.tabLayout.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
                FragmentUtils.showHide(position,fragments);
                KLog.i(position+"---");
            }

            @Override
            public void onTabReselect(int position) {

            }
        });
        binding.tabLayout.setCurrentTab(0);
    }
}